<?php
define('APP_PATH', dirname(dirname(__FILE__)));
require_once(APP_PATH . '/app.php');

$channelid = abs(intval($_G['gp_channelid']));

if( !$channel = fetch('call_center', $channelid, 'channel') ){
	jsonp('Channel Error');
}

if( is_post() ){
	$chars = array('begin_time', 'ringback_time', 'connect_time', 'end_time', 'phone', 'record', 'cname');
	$ints = array('type', 'result');
	$data = array();
	foreach( $chars as $k => $v ){
		$data[$v] = $_G['gp_' . $v] ? htmlspecialchars($_G['gp_' . $v]) : '';
	}
	foreach( $ints as $k => $v ){
		$data[$v] = $_G['gp_' . $v] ? abs(intval($_G['gp_' . $v])) : '';
	}
	$data['adminid'] = $channel['adminid'];
	$data['total'] = intval($data['end_time'] - $data['begin_time']);
	$data['talk'] = intval($data['end_time'] - $data['connect_time']);
	$data['channelid'] = $channel['id'];
	$data['create_time'] = SYS_TIME;
	$data['cname'] = $data['cname'] ? $data['cname'] : 'qd';
	$callogid = DB::Insert('call_center_log', $data);
	jsonp($callogid);
}

?>